#ifndef ELTAG_H
#define ELTAG_H

#include "../basic/elcomponent.h"
#include "../basic/eltheme.h"

class ElCircleButton;
// BUG: close button's foreground color cannot update immediately after showing.
class ElTag : public ElComponent
{
    Q_OBJECT
public:
    enum Type { Default, Success, Warning, Info, Danger };
    enum Effect { Light, Dark, Plain };

    ElTag(QWidget *parent = nullptr);
    ElTag(const QString &content, QWidget *parent = nullptr);

    QString content() const;
    void setContent(const QString &content);

    Type type() const;
    void setType(Type type);

    Effect effect() const;
    void setEffect(Effect effect);

    bool isClosable() const;
    void setClosable(bool closable);

    QColor backgroundColor() const;
    void setBackgroundColor(const QColor &bgColor);

    QColor foregroundColor() const;
    void setForegroundColor(const QColor &fgColor);

    QColor borderColor() const;
    void setBorderColor(const QColor &bdColor);

    bool isHit() const;
    void setHit(bool hit);

    static const int Padding_Lr;
    static const int Padding_Tb;
    static const int Icon_Spacing;

signals:
    void clicked();
    void closeClicked();

protected:
    void paintEvent(QPaintEvent *e) override;
    void mouseReleaseEvent(QMouseEvent *e) override;
    void initPalette() override;

private:
    Q_PROPERTY(QString content READ content WRITE setContent)
    Q_PROPERTY(Type type READ type WRITE setType)
    Q_PROPERTY(Effect effect READ effect WRITE setEffect)
    Q_PROPERTY(bool closable READ isClosable WRITE setClosable)
    Q_PROPERTY(bool hit READ isHit WRITE setHit)
    Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor)
    Q_PROPERTY(QColor foregroundColor READ foregroundColor WRITE setForegroundColor)
    Q_PROPERTY(QColor borderColor READ borderColor WRITE setBorderColor)

    QString _content;
    ElTheme _theme;
    Effect _effect = Light;
    bool _closable = false;
    bool _hit = false;
    QColor _bg = Qt::white;
    QColor _fg = ThemeColor::primaryColor;
    QColor _bd = QColor(217, 236, 255);

    ElCircleButton *_closeBtn = nullptr;

    void createCloseBtn();
    void updateCloseBtn();
};

#endif // ELTAG_H
